<?php


class Registry extends A_Content {

	
	public function getById($id) {
		throw $this->_top->Utils->PushError("Registry::getById method NOT IN USE","Системная ошибка");
	}
	
	public function add() {
		throw $this->_top->Utils->PushError("Registry::add method NOT IN USE","Системная ошибка");
	}
	
	public function __set($varible,$value) {
		return $this->setValue($varible,$value);
	}
	
	public function __get($varible) {
		$this->getById($varible);
	}
	
	
	public function setValue($varible,$value) {
		$p_varible = $this->_parent->prepareValueForSQL($varible);
		$p_value = $this->_parent->prepareValueForSQL($value);
		try {
			$this->getValue($varible);
			$this->_top->_sql->exeDummy("UPDATE `".TAB_PREF."registry`
				SET  `value`='$p_value' WHERE `regkey`='$p_varible';");
		} catch (Exception $e) {
			$this->_top->_sql->exeDummy("INSERT INTO `".TAB_PREF."registry`(`regkey`,`value`) 
				VALUE ('$p_varible','$p_value');");
		}
		return true;
	}
	
	public function getValue($varible) {
		if (!isset($this->_cashe_obj[$varible])) {
			$get_varible = $this->_top->_sql->exe("SELECT 
				  `value`
				FROM 
				  `".TAB_PREF."registry` r
				WHERE r.`regkey`='$varible'");
				
			if (count($get_varible)==0) {
				throw $this->_top->Utils->PushError("There is no value for $varible key","Системная ошибка");
			}
			
			$this->_cashe_obj[$varible] = $get_varible[0]['value'];
		}
		return $this->_cashe_obj[$varible];
	}
	
	
}

?>